package server.server01;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 封装请求信息
 */
public class Server04 {
    private ServerSocket serverCocket;
    public static void main(String[] args) {
        Server04 server = new Server04();
        server.start();
    }
//启动服务
    public void start(){
        try {
            serverCocket = new ServerSocket(8777);
            receive();
        } catch (IOException e) {
            System.out.println("服务器启动失败");
             e.printStackTrace();
        }
    }
//接受连接
    public void receive(){
        try {
            System.out.println("一个客户端建立了连接");
                Socket client =  serverCocket.accept();
                //获取请求协议
                 Request request =  new Request(client);
                //响应
                Response response = new Response(client);
                response.print("<html>");
                response.print("<head>");
                response.print("<meta charset=\"UTF-8\">");
                response.print("<title>");
                response.print("服务器响应成功");
                response.print("</title>");
                response.print("</head>");
                response.print("<body>");
                response.print("shsxt server终于回来了。。。。");
                response.print("</body>");
                response.print("</html>");

                response.pushBrower(200);

        } catch (IOException e) {
            System.out.println("客户端错误");
            e.printStackTrace();
        }
    }
//停止服务
    public void stop(){

    }
}
